//
//  DrawViewController.m
//  
//
//  Created by lanou on 16/7/2.
//
//

#import "DrawViewController.h"

@interface DrawViewController ()<MenuViewControllerDelegate>
@property (nonatomic,strong)MenuViewController *menuVC;
@property (nonatomic,strong)UINavigationController *rightVC;

@end

@implementation DrawViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    
    [self addChildViewController:self.menuVC];
    [self addChildViewController:self.rightVC];
    
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightVC.view];
    
    // Do any additional setup after loading the view.
}

- (instancetype)initWithMenuController:(MenuViewController *)menu andRightController:(RightViewController *)right{
    
    self = [super init];
    if (self) {
        self.menuVC = menu;
        self.rightVC = [[UINavigationController alloc]initWithRootViewController:right];
        self.menuVC.delegate = self;
        
    }
    
    return self;
}

- (void)menuViewControllerDidClickCellWithVC:(RightViewController *)VC{
    [UIView animateWithDuration:0.2 animations:^{
       
        self.rightVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        
    } completion:^(BOOL finished) {
        [self.rightVC removeFromParentViewController];
        [self.rightVC.view removeFromSuperview];
        
        self.rightVC = [[UINavigationController alloc]initWithRootViewController:VC];
        [self addChildViewController:self.rightVC];
        [self.view addSubview:self.rightVC.view];
        self.rightVC.view.frame = CGRectMake(kWidth, 0, kWidth, kHeight);
        
        [UIView animateWithDuration:0.2 delay:0.2 options:UIViewAnimationOptionLayoutSubviews animations:^{
            self.rightVC.view.frame = self.view.frame;
        } completion:^(BOOL finished) {
            
        }];
        
    }];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
